package com.ogawa.joypal.distributionnetwork.viewmodel

import androidx.lifecycle.MutableLiveData
import com.ogawa.base.base.BaseViewModel
import com.ogawa.base.bean.LoadState
import com.ogawa.projectcommon.utils.dataConvert
import com.ogawa.projectcommon.utils.launch
import com.ogawa.projectcommon.network.RetrofitManager
import com.ogawa.joypal.distributionnetwork.MainApiService
import com.ogawa.joypal.distributionnetwork.bean.DeviceStatusBean

class GetSnViewModel : BaseViewModel() {
    val deviceBean = MutableLiveData<DeviceStatusBean>()

    fun getSn(mac: String) {
        launch({
            loadState.value = LoadState.Loading("")
            val dataConvert = RetrofitManager.INSTANCE
                .createService(MainApiService::class.java)
                .getDeviceStatus(mac, 1)
                .dataConvert()
            deviceBean.value = dataConvert
            loadState.value = LoadState.Success("")
        }
            , { loadState.value = LoadState.Fail(it.message ?: "") }
            , {})
    }
}